import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.12
import Qt.labs.platform 1.1
import com.stupidzhe.QrCode 1.0

Window {
    visible: true
    width: 900
    height: 600
    minimumWidth: 900
    maximumWidth: 900
    minimumHeight: 600
    title: qsTr("WeFuck")
    id: root
    Loader {
        id: splashLoader
        source: "LoadingView.qml"
        anchors.fill: parent
        asynchronous: false
        visible: true
        onStatusChanged: {
            appLoader.setSource("LoginView.qml")
        }
    }

    Loader {
        id: appLoader
        anchors.fill: parent
        visible: false
        asynchronous: true
        onStatusChanged: {
            console.log("appLoader status changed")
            if (status === Loader.Error)
                splashLoader.item.errorInLoadingApp()
        }
    }
    Loader {
        id: indexLoader
        anchors.fill: parent
        visible: false
        asynchronous: false
        onStatusChanged: {
            if (status === Loader.Ready) {
                console.log("index Ready")
                appLoader.item.appReady()
            }
            if (status === Loader.Error)
                appLoader.item.errorInLoadingApp()
        }
    }
    QrCode {
        id: qrCode
        Component.onCompleted: {
            console.log("qrCode loading success!")
        }
    }

    Connections {
        target: splashLoader.item
        onReadyToGo: {
            appLoader.visible = true
            appLoader.item.init()
            splashLoader.visible = false
            splashLoader.setSource("")
            appLoader.item.forceActiveFocus()
        }
    }
    Connections {
        target: appLoader.item
        onReadyToGo: {
            indexLoader.setSource("IndexView.qml")
            indexLoader.visible = true
            appLoader.visible = false
            appLoader.setSource("")
            indexLoader.item.forceActiveFocus()
        }
    }
}
